package cn.hxzy.controller;



import cn.hxzy.domain.Courseware;
import cn.hxzy.response.R;
import cn.hxzy.response.StatusEnum;

import cn.hxzy.service.CoursewareService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author niuyi
 * @since 2024-06-22
 */
@RestController
@RequestMapping("/courseware")
public class CoursewareController {

    @Autowired
    private CoursewareService coursewareService;
    //根据小节编号查询课件
    @GetMapping("/selectWareList")
    public R<List<Courseware>> selectWareList(@RequestParam("sectionId") Integer sectionId) {

        List<Courseware> coursewares = coursewareService.selectWareList(sectionId);
        if (coursewares != null){
            return R.success(coursewares);
        }
        return R.error(401,"查询失败");
    }
    /**
     * 搜索框搜索课件
     * @param sectionId
     * @return
     */
    @GetMapping("/selectWare")
    public R selectWare(@RequestParam("sectionId") Integer sectionId,@RequestParam("coursewareName") String coursewareName) {
        return R.success(new Courseware());
    }
    //根据课件编号删除课件
    @Delete("/deleteWare")
    public R deleteWare(@RequestParam("coursewareId") Integer coursewareId) {
        return R.success("删除成功");
    }
    //新增课件
    @PostMapping("insertWare")
    public R insertWare(@RequestBody Courseware courseware) {
        return R.success("新增成功");
    }
    //修改课件名称
    @PatchMapping("/updateWareName")
    public R updateWareName(@RequestParam("coursewareId") Integer coursewareId,@RequestParam("coursewareName") String coursewareName) {
        return R.success("修改成功");
    }
    //修改课件
    @PatchMapping("/updateWare")
    public R updateWare(@RequestParam("coursewareId") Integer coursewareId,@RequestParam("coursewarePath") String coursewarePath) {
        return R.success("修改成功");
    }
    //新增小节的课件
    @PostMapping("/saveCourseware")
    public R saveVideo(@RequestBody Courseware courseware) {
        boolean save = coursewareService.save(courseware);
        if (save){
            return R.success(save);
        }
        return R.error(StatusEnum.SERVICE_ERROR);
    }

}

